package com.yzs.mvidemo.demo

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.yzs.core.base.BaseViewModel
import com.yzs.core.ext.asLiveData
import com.yzs.core.repository.DemoRepo


class DemoVM : BaseViewModel() {
    private val repo by lazy { DemoRepo(viewModelScope, _viewStates) }

    // 如果想要方便 也可以直接提供给上层 MutableLiveData 单要管理好 数据倒灌的问题
    private val _liveData = MutableLiveData<String>() // vm、repo 中可以 set、get
    val liveData = _liveData.asLiveData() // 提供给上层 只允许 监听

    fun dispatch() {
        repo.getData(_liveData)
    }
}